home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / business / stata2 / data.kit next >
Encoding:
Text File  |  1988-08-16  |  6.7 KB  |  260 lines

  1. set output error
  2.  
  3. display _new in blue /*
  4. */ "Loading Data.Kit Release 2.0  Demonstration Version" _n /*
  5. */ "Copyright (c) 1987-1988 by ==C=R=C==.  All rights reserved."
  6.  
  7.  
  8. * routines used by collapse:
  9.  
  10. capture program drop _sums
  11. program define _sums
  12.     by %_1: replace %_2=sum(%_2)
  13. end
  14.  
  15. capture program drop _means
  16. program define _means
  17.     by %_1: replace %_2=sum(%_2)/sum(%_2~=.)
  18. end
  19.  
  20. capture program drop _medians
  21. program define _medians
  22.     sort %_1 %_2
  23.     by %_1: gen _CNT=sum(%_2~=.)
  24.     by %_1: replace %_2= /*
  25.                 */ (%_2[(_CNT[_N]+1)/2]+%_2[(_CNT[_N]+2)/2])/2 if _n==_N
  26.     by %_1: replace %_2=%_2[_N]
  27.     drop _CNT
  28. end
  29.  
  30.  
  31. * top level programs
  32.  
  33. capture program drop recast
  34. program define recast
  35.         if "%_2"=="" | "%_3"~="" {
  36.                 di in bl "->recast varname type"
  37.                 exit
  38.         }
  39.         confirm var %_1
  40.         capture gen %_2 _recast = %_1
  41.         if _rc {
  42.                 di in red "%_2 invalid type for %_1"
  43.                 exit
  44.         }
  45.         capture {
  46.                 count if %_1~=_recast
  47.                 if _result(1)>0 {
  48.                         di in red _result(1), /*
  49.                           */   "values would be changed.  No action taken."
  50.                         drop _recast
  51.                         exit
  52.                 }
  53.                 mac def _varl : variable label %_1
  54.                 label var _recast "%_varl"
  55.                 capture confirm string var _recast
  56.                 if _rc {
  57.                         mac def _val : value label %_1
  58.                         label val _recast %_val
  59.                         mac def _fmt  : format %_1
  60.                         format _recast %_fmt
  61.                 }
  62.         }
  63.         if _rc {
  64.                 di in red "--Break--"
  65.                 capture drop _recast
  66.                 exit
  67.         }
  68.         drop %_1
  69.         rename _recast %_1
  70. end
  71.  
  72.  
  73. * order deleted
  74.  
  75. capture program drop order
  76. program define order
  77.     di in blue "not available in demonstration version"
  78. end
  79.  
  80.  
  81. capture program drop collapse
  82. program define collapse
  83.     if "%_*"=="" { 
  84.         di in bl /* 
  85.          */    "-> collapse varlist [if] [in], by(varname) [means medians sums]"
  86.         di in bl _col(31) "nowarning"
  87.         exit
  88.     }
  89.     mac def _varlist "req ex"
  90.     mac def _options "BY(string) SUms MEAns MEDians noWarning"
  91.     mac def _if "opt"
  92.     mac def _in "opt"
  93.     parse "%_*"
  94.     capture conf ex %_by
  95.     if _rc {
  96.         di in red "by(variable) required"
  97.         exit
  98.     }
  99.     conf var %_by
  100.     mac def _type "means"
  101.         if "%_sums"~="" { mac def _type "sums" } 
  102.         if "%_medians"~="" { mac def _type "medians" } 
  103.     if "%_warning"=="" { 
  104.         di in red "Warning: " in bl "Data in memory will be destroyed."
  105.         di _col(10) in bl /* 
  106.         */ "Press any key to continue, Ctrl-Break to abort."
  107.         more
  108.     }
  109.     quietly {
  110.         keep %_varlist %_by
  111.         if "%_if"~="" | "%_in"~="" {
  112.             keep %_if %_in
  113.         }
  114.         sort %_by
  115.         parse "%_varlist", parse(" ")
  116.         while "%_1"~="" { 
  117.             _`%_type "%_by" %_1
  118.             mac shift
  119.         }
  120.         by %_by: keep if _n==_N
  121.         label data "%_type by %_by"
  122.     }
  123.     desc
  124. end
  125.  
  126. capture program drop mdytoe
  127. program define mdytoe
  128.     if "%_*"=="" {
  129.         di in bl "-> mdytoe mo da yr [if] [in], gen(evar)"
  130.         exit
  131.     }
  132.     mac def _varlist "req ex min(3) max(3)"
  133.     mac def _if "opt"
  134.     mac def _in "opt"
  135.     mac def _options "Generate(string)"
  136.     parse "%_*"
  137.     if "%_generat"=="" {
  138.         mdytoe
  139.         exit
  140.     }
  141.     conf new var %_generat
  142.     mac def _Exp "int(((%_1)-14)/12)"
  143.     parse "%_varlist", parse(" ")
  144.     #delimit ;
  145.     gen long %_generat =
  146.          (%_2) - 2469010 + int(1461*((%_3)+4800+%_Exp)/4)
  147.            + int(367*((%_1)-2-%_Exp*12)/12)
  148.            - int(3*int(((%_3)+4900+%_Exp)/100)/4) %_if %_in;
  149.     #delimit cr
  150. end
  151.  
  152. capture program drop etomdy
  153. program define etomdy
  154.     if "%_*"=="" {
  155.         di in bl "etomdy evar [if] [in], gen(mo da yr)"
  156.         exit
  157.     }
  158.     mac def _varlist "req ex max(1)"
  159.     mac def _if "opt"
  160.     mac def _in "opt"
  161.     mac def _options "Generate(string)"
  162.     parse "%_*"
  163.     parse "%_generat", parse(" ")
  164.     if ("%_3"=="" | "%_4"~="") {
  165.         etomdy
  166.         exit
  167.     }
  168.     conf new var %_*
  169.     capture {
  170.         gen long _Temp2 = int(4*((%_varlist)+2505504)/146097) %_if %_in
  171.         gen long _Temp1  = (%_varlist) + 2505504 - /*
  172.                    */   int((146097*_Temp2+3)/4) %_if %_in
  173.         gen int %_3 = int(4000*(_Temp1+1)/1461001) %_if %_in
  174.         replace _Temp1 = _Temp1 - int(1461*%_3/4) + 31 %_if %_in
  175.         gen int %_1 = int(80*_Temp1/2447) %_if %_in
  176.         gen int %_2 = _Temp1 - int(2447*%_1/80) %_if %_in
  177.         replace _Temp1 = int(%_1/11) %_if %_in
  178.         replace %_1 = (%_1) + 2 - 12*_Temp1 %_if %_in
  179.         replace %_3 = 100*(_Temp2-49) + (%_3) + _Temp1 %_if %_in
  180.         drop _Temp1 _Temp2
  181.         exit
  182.     }
  183.     di in red "--Break--"
  184.     capture drop _Temp1
  185.     capture drop _Temp2
  186.     capture drop %_3
  187.     capture drop %_2
  188.     capture drop %_1
  189. end
  190.  
  191.  
  192. capture prog drop etodow
  193. program define etodow
  194.     if "%_*"=="" {
  195.         di in bl "-> etodow evar [if] [in], gen(dowvar)"
  196.         exit
  197.     }
  198.     mac def _varlist "req ex max(1)"
  199.     mac def _if "opt"
  200.     mac def _in "opt"
  201.     mac def _options "Generate(string)"
  202.     parse "%_*"
  203.     parse "%_generat", parse(" ")
  204.     if "%_1"=="" | "%_2"~="" {
  205.         etodow
  206.         exit
  207.     }
  208.     conf new var %_generat
  209.     #delimit ;
  210.     gen int %_generat = cond((%_varlist)+5==0,0,
  211.                             cond((%_varlist)>=0,mod((%_varlist)+5,7),
  212.                             6-mod(abs(%_varlist)+8,7)))
  213.             %_if %_in ;
  214.     label define Dayslab 0 "Sun." 1 "Mon." 2 "Tue." 3 "Wed."
  215.                  4 "Thu." 5 "Fri." 6 "Sat.", modify ;
  216.     #delimit cr
  217.     label values %_generat Dayslab
  218. end
  219.  
  220.  
  221. di
  222. di in gr "The following new commands are now available:"
  223. di "   collapse       etodow         mdytoe         order          recast"
  224. di "   etomdy
  225. di _n in gr "See " in wh "help data.kit" in gr "."
  226. exit
  227.  
  228.  
  229. Notes to User's wishing to edit this file:
  230.  
  231. These comments are placed at the end of the file, after the exit, so that
  232. Stata does not have to read through them every time the user types "run
  233. Graph.Kit"
  234.  
  235. Feel free to edit this file and delete programs in which you have no interest.
  236. Before editing this file, however, make sure the the original is BACKED UP.
  237. Please do not remove the copyright notice at the top of this file.
  238.  
  239. If you do edit the file, you should add a display command at the top of this
  240. file indicating that you have edited the file.  You should change the display
  241. just above these comments that lists the new commands now available.
  242.  
  243. All utility programs start with an underscore '_'.
  244.  
  245. Some programs use other programs in achieving the desired result.  Review the
  246. table below carefully before deleting programs.
  247.  
  248.         Program         Requires
  249.         --------------------------
  250.         collapse        _sums  _means  _medians
  251.         order
  252.         mdytoe
  253.         etomdy
  254.         etodow
  255.         recast
  256.  
  257. For instance, if you deleted the _sums program, you would break collapse.
  258.  
  259. <end of Data.Kit>
  260.